-
Notifications
You must be signed in to change notification settings - Fork 93
feat: rework IPRateLimiter with Redis integration #4662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: rework IPRateLimiter with Redis integration #4662
Conversation
Test Results 20 files ± 0 261 suites - 12 20m 48s ⏱️ - 1m 30s For more details on these failures, see this check. Results for commit 59f6388. ± Comparison against base commit 75f8196. This pull request removes 36 and adds 1 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
jasuwienas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@quiet-node It looks great overall! There’s just one thing I’m wondering about.
jasuwienas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm @quiet-node
There’s one thing I dislike in our code (not introduced in this PR). Sometimes, when we create new interfaces, we prefix them with I (e.g., ICacheClient, IAccountInfo, IFeeHistory, and many others), and other times we don’t (e.g., the TxPool interfaces, global config, RateLimitStore, etc.). Maybe we should consider addressing this inconsistency later.
| this.logger = logger.child({ name: 'redis-rate-limit-store' }); | ||
| this.duration = duration; | ||
| this.rateLimitStoreFailureCounter = rateLimitStoreFailureCounter; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amaziing, much cleaner!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great glad you find it better!
|
|
||
| describe('create', () => { | ||
| it('should return LruRateLimitStore when redisClient is not provided', () => { | ||
| const store = RateLimitStoreFactory.create(logger, testDuration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't not provided and undefined basically the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was thinking to not provided anything with undefined but with the counter. But you're right it's basically the same. I'll remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it
Yessir I definitely agree. Consistency makes everything so much more organized and tuitive! But yeah the I-prefixed-interfaces were the old ones and we're aiming to drop the I-prefix. That said we should have a new PR in future to align everything, even with the linting as well. |
c3b7928
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
c3b7928 to
59f6388
Compare
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #4662 +/- ##
==========================================
- Coverage 95.67% 95.62% -0.05%
==========================================
Files 131 132 +1
Lines 21028 20989 -39
Branches 1785 1761 -24
==========================================
- Hits 20118 20071 -47
- Misses 892 903 +11
+ Partials 18 15 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Description
This PR:
RateLimitStoreFactoryto encapsulate the logic for selecting the storage implementation based on configuration.IPRateLimiterServiceto accept aRateLimitStoreinterface in its constructor.RedisRateLimitStoreto accept aRedisClientin its constructor instead of creating it internally.server.tsandwebSocketServer.tsto use the factory and inject the store.Related issue(s)
Fixes #4599
Changes from original design (optional)
RedisRateLimitStoreto accept aRedisClientin its constructor instead of creating it internally.Additional work needed (optional)
N/A
Checklist